﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace BuildARoute.Models
{
    public class UserToolsViewModel : ViewModelBase
    {
        private Visibility _toolsVisibility;
        public Visibility ToolsVisibility 
        {
            get 
            {
                return _toolsVisibility;
            }
            set
            {
                if (_toolsVisibility != value)
                {
                    _toolsVisibility = value;
                    OnPropertyChanged("ToolsVisibility");
                }
            }
        }
        private Visibility _unauthenticatedVisibility;
        public Visibility UnauthenticatedVisibility
        {
            get
            {
                return _unauthenticatedVisibility;
            }
            set
            {
                if (_unauthenticatedVisibility != value)
                {
                    _unauthenticatedVisibility = value;
                    OnPropertyChanged("UnauthenticatedVisibility");
                }
            }
        }

        #region methods and event handlers
        public UserToolsViewModel()
        {
            WebContext.Current.Authentication.LoggedIn += (s, e) => UpdateVisibilitiesForAuthenticationStatus();
            WebContext.Current.Authentication.LoggedOut += (s, e) => UpdateVisibilitiesForAuthenticationStatus();
            UpdateVisibilitiesForAuthenticationStatus();
        }
        private void UpdateVisibilitiesForAuthenticationStatus()
        {
            bool isLoggedIn = WebContext.Current.User.IsAuthenticated;

            ToolsVisibility = isLoggedIn ? Visibility.Visible : Visibility.Collapsed;
            UnauthenticatedVisibility = isLoggedIn ? Visibility.Collapsed : Visibility.Visible;
        }
        #endregion


    }
}
